﻿using IdentityModel;
using IdentityServer4.Models;

namespace MyWeb.Ids4Authorization
{
    public class OAuthData
    {
        /// <summary>
        /// 配置api范围
        /// </summary>
        /// <returns></returns>
        public static IEnumerable<ApiScope> GetApiScopes()
        {
            return new List<ApiScope>
            {
                new ApiScope(Config.UserApi.ApiName)
            };
        }

        #region API资源
        /// <summary>
        /// Api 资源
        /// </summary>
        /// <returns></returns>
        public static IEnumerable<ApiResource> GetApiResources()
        {
            return new List<ApiResource>
            {
                new ApiResource(
                    Config.UserApi.ApiName,
                    Config.UserApi.ApiName,
                    new List<string>(){JwtClaimTypes.Role }
                    ),
            };
        }
        #endregion

        /// <summary>
        /// Api 客户端
        /// </summary>
        /// <returns></returns>
        public static IEnumerable<Client> GetClients()
        {
            return new List<Client>
            {
                #region OAuth 2.0 Demo Client
                new Client()
                {
                    ClientId =Config.UserApi.ClientId,
                    AllowedGrantTypes = new List<string>()
                    {
                        "password"
                        //GrantTypes.ResourceOwnerPassword.FirstOrDefault(),
                        //Resource Owner Password模式
                        //GrantTypeConstants.ResourceWeixinOpen,
                    },
                    ClientSecrets = {new Secret(Config.UserApi.Secret.Sha256()) },
                    AllowOfflineAccess = true,//如果要获取refresh_tokens ,必须把AllowOfflineAccess设置为true
                    AllowedScopes= {
                        Config.UserApi.ApiName,
                        //StandardScopes.OfflineAccess,
                    },
                    AccessTokenLifetime = Config.ExpireIn,
                },
                #endregion
            };
        }
    }
}
